﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace PrintPack
{
    public class BusinessPackingRecord
    {
        public static string strSqlConnection4_608FFCPACKING = ConfigurationManager.AppSettings.Get("FFCPACKINGCONNECTION").ToString();
        public System.Data.SqlClient.SqlConnection sqlConnection4;
        public BusinessPackingRecord()
        {
           // strSqlConnection4_608FFCPACKING = ConfigurationManager.AppSettings.Get("FFCPACKINGCONNECTION").ToString();
        }

        public DataTable PackingGetDatabyBOX(string BoxNumber)
        {
             using (sqlConnection4 = new SqlConnection(strSqlConnection4_608FFCPACKING))
            {
                sqlConnection4.Open();

                #region Kiem tra Prod Order trong T_information
                string result = "Kiem tra ProdOrder trong T_information";
                
                SqlCommand cmdGetProdOrderSerials = sqlConnection4.CreateCommand();
                cmdGetProdOrderSerials.CommandType = CommandType.StoredProcedure;
                cmdGetProdOrderSerials.CommandText = "PackingRecord_GetByBox";

                cmdGetProdOrderSerials.Parameters.Add("@BoxNumber", SqlDbType.Char, 20);
                cmdGetProdOrderSerials.Parameters["@BoxNumber"].Value = BoxNumber;
                cmdGetProdOrderSerials.Parameters["@BoxNumber"].Direction = ParameterDirection.Input;
                
                SqlDataReader rec = cmdGetProdOrderSerials.ExecuteReader();
                rec.Read();

                result = rec[0].ToString();
                #endregion


                if (result.Equals("OK"))
                {

                    //TraceStepDoing("Doc thong Tinformation ");


                    //rec.NextResult();
                    //rec.Read();
                    //strPN = rec["T_ProdOrder"].ToString().Trim();
                    //strProductmap = rec["T_ProductMap"].ToString().Trim();
                    //strPN = rec["T_Material"].ToString().Trim();
                    //strRev = rec["T_Revision"].ToString().Trim();
                    //StrDes = "";
                    //string tmpProductMap = getProductMapDetail(strPN, ref StrDes);
                    //intPOQuantity = Int32.Parse(rec["T_Quantity"].ToString().Trim());
                    //intPOPacked = Int32.Parse(rec["T_Packed"].ToString().Trim());
                    sqlConnection4.Close();

                }

                DataTable d = new DataTable();
                d.Load(cmdGetProdOrderSerials.ExecuteReader());
                cmdGetProdOrderSerials.Dispose();
                
                sqlConnection4.Close();
                return d;



            }
        }


        private void ReadInforFromT_Information(string PO, ref string strPN, ref string strRev, ref string StrDes, ref string strProductmap)
        {


            using (sqlConnection4 = new SqlConnection(strSqlConnection4_608FFCPACKING))
            {
                sqlConnection4.Open();

                #region Kiem tra Prod Order trong T_information
                string result = "Kiem tra ProdOrder trong T_information";
                PO = (PO).PadLeft(12, '0');

                SqlCommand cmdGetProdOrderSerials = sqlConnection4.CreateCommand();
                cmdGetProdOrderSerials.CommandType = CommandType.StoredProcedure;
                cmdGetProdOrderSerials.CommandText = "ame_T_getProdOrderInfo"; ;
                cmdGetProdOrderSerials.Parameters.Add("@ProdOrder", SqlDbType.Char, 20);
                cmdGetProdOrderSerials.Parameters["@ProdOrder"].Value = PO;
                cmdGetProdOrderSerials.Parameters["@ProdOrder"].Direction = ParameterDirection.Input;
                SqlDataReader rec = cmdGetProdOrderSerials.ExecuteReader();
                rec.Read();

                result = rec[0].ToString();
                #endregion


                if (result.Equals("OK"))
                {

                    //TraceStepDoing("Doc thong Tinformation ");


                    rec.NextResult();
                    rec.Read();
                    strPN = rec["T_ProdOrder"].ToString().Trim();
                    strProductmap = rec["T_ProductMap"].ToString().Trim();
                    strPN = rec["T_Material"].ToString().Trim();
                    strRev = rec["T_Revision"].ToString().Trim();
                    StrDes = "";
                    //string tmpProductMap = getProductMapDetail(strPN,ref StrDes); 
                    //intPOQuantity = Int32.Parse(rec["T_Quantity"].ToString().Trim());
                    //intPOPacked = Int32.Parse(rec["T_Packed"].ToString().Trim());
                    sqlConnection4.Close();

                }





            }
        }


    }
}
